Part Number Hot Search : 
11N60S5 E0052 657EWT MA6X128 M74HC173 LT1058 02001 PA28F200
Product Description
Full Text Search
 

To Download AN4232 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  january 2015 docid024134 rev 2 1/17 1 AN4232 application note getting started with analog comparators for stm32f3 series introduction this document describes the main features of the analog comparator embedded in stm32f3 series. the application cases are: ? cy cle-by-cycle current control ? fr equency and pulse width measurement ? analog voltage monitoring ? preventing false over-current detections in motor control applications ? humidity measurement the five application cases demonstrate the usefulness of analog comparators and show ho w th ey are integrated with other peripherals, for example, the digital-to-analog-converter (dac) and timers. to ensure a quick start, some application cases presented in this document are imp l emented in c language and are available in the stm32f30x and stm32f37x dsp and standard peripherals library packages. please note that this document is not intend ed to re place the analog comparator (comp) section in the product reference manual. all values given in this document are for guidance only. please refer to the related datasheet for guaranteed and up-to-date values. throughout this document: ? stm3 2f30x refers to the stm32f301, stm32f302, stm32f303, stm32f3x8, stm3 2f328, stm32f358, stm32f398 and stm32f334. ? stm32f37x refers to the stm32f373 and stm32f378 product lines. www.st.com
contents AN4232 2/17 docid024134 rev 2 contents 1 overview of analog comparators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1 hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 propagation delay (response time) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 application examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.1 cycle-by-cycle current control (peak current control) . . . . . . . . . . . . . . . . . 8 2.2 frequency and pulse width measurement . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 analog voltage monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.4 preventing false over-current detections in motor control applications . . 12 2.5 humidity measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
docid024134 rev 2 3/17 AN4232 list of tables 3 list of tables table 1. applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. typical values of an hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 table 3. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
list of figures AN4232 4/17 docid024134 rev 2 list of figures figure 1. effect of a noisy input on a comparator output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 figure 2. waveform of a comparator output with and without an hysteresis . . . . . . . . . . . . . . . . . . . . 6 figure 3. propagation delay in analog comparators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 4. block diagram of cycle-by-cycle current control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 5. comparator outpu t capability in low-power mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 figure 6. current consumption in an analog voltage monito ring application . . . . . . . . . . . . . . . . . . . 11 figure 7. comparator output blanking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 8. block diagram of the humidity measurement applicat ion . . . . . . . . . . . . . . . . . . . . . . . . . . 14
docid024134 rev 2 5/17 AN4232 overview of analog comparators 16 1 overview of analog comparators 1.1 hysteresis a comparator compares the inverting input with the non-inverting input and even small voltage fluctuations cause bounce on comparator the output. this bounce is not acceptable in many applications. figure 1 shows the output bouncing when the input is noisy. figure 1. effect of a noisy input on a comparator output this bounce on the comparator output can be prevented by adding hysteresis into comparators. the analog comparators in stm32f37x and stm32f30x devices have a configurable hysteresis value: no, low, medium and high hysteresis value. table 2 shows the typical values of an hysteresis in each configuration. caution: th e hysteresis feature is not available on the following microcontrollers: stm32f301x6/8, stm32f302x6/8, stm32f303x4/6/8, stm32f334xx, stm32f302xd/e and stm32f303xd/e. 069
overview of analog comparators AN4232 6/17 docid024134 rev 2 figure 2. waveform of a comparator output with and without an hysteresis 1.2 propagation delay (response time) another important feature of the analog comparat or is the propagation delay. this delay is defined as the time between the moment the input signal crosses the threshold and the moment the output state changes (usually when the output reaches 50% of v dd ). there is a trade off between the comparator propagation delay and the power consumption: the faster the comparator goes, the more it consumes power. in stm32f302xb/c, stm32f303xb/c and st m3 2f37x devices, the operation mode (speed/power consumption) is configurable ma king it useful for both low-power applications (such as voltage monitoring) and critical ti me applications (such as motor control). the analog comparators in stm32f30x and stm32f37x devices can operate at low speed/low power with 2 s/1.2 a and can also operate at high sp eed/high power with 50 ns/75 a. table 2. typical values of an hysteresis hysteresis typical value no hysteresis 0 mv low hysteresis 8 mv medium hysteresis 15 mv high hysteresis 31 mv ,?????]?v ,qyhuwlqj ,qsxw &rpsdudwru rxwsxw 1rqlqyhuwlqj ,qsxw &rpsdudwru2xwsxwzlwkk\vwhuhvlv &rpsdudwru2xwsxwzlwk qrk\vwhuhvlv .47
docid024134 rev 2 7/17 AN4232 overview of analog comparators 16 figure 3. propagation delay in analog comparators note: in the stm32f301x6/8, stm32f302x6/8, stm32f303x4/6/8, stm32f302xd/e stm32f303xd/e, the programmable speed/cons umption feature is not available. the propagation delay is 25 ns typical. 1rqlqyhuwlqjlqsxw ,qyhuwlqjlqsxw wkuhvkrog 3ursdjdwlrqghod\ &rpsdudwru rxwsxw 7lph 9 '' 069
application examples AN4232 8/17 docid024134 rev 2 2 application examples this section describes how the analog comparators embedded in stm32f30x and stm32f37x devices can be used in applicativ e examples such as humidity measurement, cycle-by-cycle motor control, voltage monitoring, and pwm control. 2.1 cycle-by-cycle current control (peak current control) cycle-by-cycle current control (a lso called peak current control) is a technique broadly used for power conversion, typically for dc-dc converters, lighting or motor drives. the current sensor output (for instance a shunt or a current transformer) is connected to the comparator non-inverting (i sensed ) input and compared against a current limit which is set on the inverting input (either a simple resistor divider or the embedded dac if the set-point has to be adjusted dynamically). when the monitored current exceeds the current limit, the comparator output goes high and disables the pwm outputs for the remaining time in the pwm cycle. on the next cycle, if the comparator output is back to zero (i.e. the current is below the limit), the pwm output is enabled again. as displayed in figure 4 , stm32f30x and stm32f37x devices are designed for these kinds of applications, where the timer can be used in pwm mode to control the motor. the a nalog comparator can be used to monitor the motor current on-the-fly. the comparator output can be internally redirected to the o crefclr signal which controls the pwm state. the embedded digital analog converter can be inte rnally connected to the inverting input of the comparator. in figure 4 . both the real pwm (solid line) and the programmed pwm (dotted line) values (if there were no ocrefclr feedback) are displayed.
docid024134 rev 2 9/17 AN4232 application examples 16 figure 4. block diagram of cycle-by-cycle current control &xuuhqwwkuhvkrog , uhi &rpsdudwrulqyhuwlqjlqsxw , uhi &rpsdudwruqrqlqyhuwlqjlqsxw , vhqv 2&5()&/5 2&5()&/5 2&5()&/5 7lph 9rowdjh 9rowdjh 7lph &rpsdudwrurxwsxw 7,0 frxqwhu 7,0 suhvfdohu 'ljlwdo frpsdudwru 2xwsxw frqwuro 3:0rxwsxw , vhqvhg ,uhi vhwe\'$&  &rpsdudwru rxwsxw &rpsdudwru rxwsxw $3%[forfn 7lphu 3urjudpphg7,03:0 5hdo7,03:0 069
application examples AN4232 10/17 docid024134 rev 2 2.2 frequency and pul se width measurement in stm32f30x and stm32f37x devices, the comp arator output can be redirected to the input capture of the embedded timers. this fe ature allows a pulse width and/or frequency measurement. the input signal, whose signal width/frequency has to be measured, is connected to the non-inverting input of the analog comparator. the threshold (reference) can be powered by: ? the internal referenc e voltage v refint (1.22v) and sub-multiples (1/4 v refint , 1/2 v refint , 3/4 v refint ) ? the embedded digital-to-analog converters ? an external pin the comparator output is redirected internally t o the input capture. in this mode, the timer counter is captured at each effective edge. when the input signal goes higher than the reference voltage, the comparator output is set to a high level generating a rising edge on the timer input capture, and the timer counter is captured in the internal register. when the input signal goes lower than the reference voltage, the comparator output is set to a low level generating a falling edge an d the timer counter is captured a second time in the internal register. the time elapsed between the two consecutive c aptures represents the pulse width. hence, the pulse width measurement is performed by a simple subtraction of the second and the first capture. 2.3 analog voltage monitoring stm32f30x and stm32f37x devices embed a 12-bit analog-to-digital converter (adc) which is very fast with a sampling rate in the order of several mega samples per second. however, with a typical consumption of 1 ma, it may not be suitable for battery-powered applications if it is left po wered-on continuously. it is ther efore useful to use an analog comparator in application cases where an analog voltage (sensor output) needs to be measured only when a predefined threshold is exceeded. in stm32f30x and stm32f37x devices, the analog comparators are designed to work ev en in low-power modes (sleep mode and stop mode). they are still powered-on and so they are able to wake-up the m cu from low-power modes. in fact, the comparator output is connected to the exti controller which also remains powered-on in lower-power modes. figure 5. comparator output cap ability in low-power mode moreover, the comparator input is an adc channel so pcb designer doesn't need to make a n external connection between the comparator input and the adc channel. in an analog voltage monitoring application where the sensor output voltage is lower than th e threshold, the mcu remains in stop mode thereby saving power. as soon as the sensor output exceeds the threshold, the analog comparator wakes up t he mcu, the adc is 1rqlqyhuwlqjlqsxw ,qyhuwlqjlqsxw 2xwsxw (;7, frqwuroohu $qdorjfrpsdudwru 069
docid024134 rev 2 11/17 AN4232 application examples 16 powered on, and the analog input voltage is measured. when the sensor output is lower than the threshold, the mcu re-enters t he low-power mode to save battery life. enabling the adc only when required (analog voltage higher than a threshold) dramatically reduces the average power consumption, as compared to an application where the adc is always enabled whatever the analog voltage. note: when an external signal needs to be monitored within a certain voltage range or window, w indow mode can be used. in this mode, the non-inverting inputs of comparators comp1 and comp2 are connected together and the input signal must be connected to the non- inverting input of comp1. in stm32f30x devices, window mode is available for comp3/comp4 and comp 5/comp6. figure 6. current consumption in an analog voltage monitoring application $yhudjhfxuuhqw :dnh xs 7lph &xuuhqw d]u 6hqvrurxwsxw yrowdjh 7kuhvkrog :dnh xs orzsrzhu prgh )hz?$ orzsrzhu prgh )hzp$ uxqprgh &rpsdudwrurxwsxw &rpsdudwruqrqlqyhuwlqjlqsxw &rpsdudwrulqyhuwlqjlqsxw 069
application examples AN4232 12/17 docid024134 rev 2 2.4 preventing false over-current detections in motor control applications note: the output blanking feature is only available on stm32f30x devices. at pwm startup, a very high current flows thro ugh the current shunt during a short time and may be seen by the comparator as greater than the inverting input. in this case, the comparator output will be set and may gener ate an unwanted emergency stop if the comparator is connected to the timer break input. this startup current is acceptable at the beginning of pwm periods and must not be managed by the comparator as a fault current (short-circuit, overload, ground fault, etc.) in stm32f30x devices, the analog comparator outpu t can be blanked using a timer output as a blanking source. the blanking source is selected/configured by software and is anded with the comparator output, resulting in a final comparator output which is not high during the peaks at the beginning of the pwm periods. figure 7 shows how the comparator output is anded with a timer output in order to blank the comparator output for a programmed duration. the same tim as the one used for the pwm ge neration can also be used for comparator blanking. figure 7. comparator output blanking an example code written in c language is available in the pr oject\stm32f30x_stdperiph_exa mples\comp\comp_outputblanking folder in the stm32f30x_dsp and standard peripherals library package stm32f30x_dsp_stdperiph_lib . note: in stm32cubef3 firmware package this example is available in the pr ojects\stm32303c_eval\examples\ comp\comp_outputblanking and the projects\stm32303e_eval\examples\co mp\comp_outputblanking folders. 069 &xuuhqwolplw &xuuhqw 5dzfrpsrxwsxw %odqnlqjzlqgrz )lqdofrpsrxwsxw 3:0 &rpsrxw %odqn &rpsrxw wr7,0b%.?
docid024134 rev 2 13/17 AN4232 application examples 16 the comp_outputblanking example aims at showing how the blanking feature can be used. in this example, comp1 is configured as follows: ? t he non-inverting input is connected to pa1 ? the inverting input is connected to v refint (1.22v) ? the output is available on pa0 ? the output is redirected to tim1 bkin to generate a break event when the non- inverting input is at a higher voltage than the inverting input (v refint ) ? tim1 oc5 is used as a blanking source tim1 is configured as follows: ? tim1 period is apb2 clock / period = 72000000 /50000 = 1440 hz ? tim1 ch2 (pa9) configured in pwm mode with a frequency equal to 1440 hz and a duty cycle pulse/period = 100 * (37500/50000) = 75% ? tim1 oc5 (internal channel: not available on gpio) configured in pwm mode with a frequency equal to 1440 hz and a high level equal to pulse/period = 2000/72000000 = 27.7 microseconds ? a break event is generated at a high polari ty (when the non-inverting input is at a higher voltage than the inverting input) note: in stm32cubef3 firmware package this example is available in the pr ojects\stm32303c_eval\examples\comp\comp_outputblanking and the projects\stm32303e_eval\examples\co mp\comp_outputblanking folders. 2.5 humidity measurement the analog comparators can be connected internally to input capture of embedded timers. this feature makes it easy to measure the capacitance values using the charge/discharge method. this ?humidity measurement? app lication is based on the hs1100/hs1101 capacitive relative humidity sensor available in the stm32303c-eval and stm32303e- eval evaluation boards. note: the application so u rce code is available in the project\stm32f30x_stdperiph_examples\ comp\comp_hygrometer folder in the stm32f30x_dsp and standard peripherals library package, stm32f30x_dsp_stdperiph_lib. in stm32cubef3 firmware package this example is available in the pr ojects\stm32303c_eval\examples\comp\comp_hygrometer and the projects\stm32303e_eval\examples\comp\comp_hygrometer folders. the capacitance measurement is performed us ing the variation of rxc time constant. a square signal generated by tim4 is passed through a charge resistance to charge/discharge the capacitive sensor. the voltage on the sensor (uc) is derived from the equation below: uc = v dd x (1? (?t/(rxc) ) where: ?v dd is the mcu power supply ? r is the charge resistance ? c is the capacitance of the sensor.
application examples AN4232 14/17 docid024134 rev 2 here is how the peripherals used are configured: 1. comp4 is configured as follows: a) the inverting input is connected to dac1 b) the non inverting input is connected to the humidity sensor c) the output is connected internally to tim4 channel 2 (configured in input capture mode). 2. tim4 is clocked at 72 mhz and tim4 channel 2 is configured in input capture mode to me asure the time constant. 3. tim3 is clocked at 72 mhz ch annel 3 and configured in pwm mode with the duty cycle at 50%. 4. dac1 is used to set the threshold (reference) and it is equal to 2.85v. it is internally conn ected to comp4 inverting input. figure 8 shows the block diagram of the application and how the peripherals used are inter- connected. figure 8. block diagram of the humidity measurement application 069 ,qsxwfdswxuh dyhudjhgydoxh 7,0,54qkdqgohu 7uljjhufrqwuro 6odyh 36& 7,0frxqwhu ,& '$& 9uhi,qw 2&3:0 36& 7,0frxqwhu 7uljjhufrqwuro 0dvwhu 6\vwhpfruhforfn 7,0hqdeoh &rps 670)[[ 0lfurfrqwuroohu ([whuqdo frpsrqhqwv 3% 3& +6/) 5hihuhqfhyrowdjh vhohfwlrq r = n>@
docid024134 rev 2 15/17 AN4232 application examples 16 when non-inverting comp4 crosses the dac1 level, the formula to compute the capacitance value is: triggertime = res * capacitance * ln(v dd /(v dd ? v ref )) where: ? triggertime is the time when the capture event occurred ? res is the charge resistan ce. its value is 82.5 k 1% ? capacitance is the capacitance value of the humidity sensor ?v dd is the device power supply. it is equal to 3.3v ?v ref is the threshold generated by the dac1 at v ref = 2.086v (generated by dac), ln(v dd /(v dd ? v ref )) is ~ 1. thus, the triggertime = res * capacitance, th e capacitance = triggertime/res by the consequent capacitance = (icreadvalue/systemcoreclock)/res where: ? icreadvalue is the captured tim4 counter ? systemcoreclock is the fre quency at which the device (specifically tim3 and tim4) is running. once the capacitance has been computed, the humidity value is given by: rh (%) = -3.4656*10 3 * x 3 + 1.0732*10 4 * x 2 - 1.0457*10 4 *x + 3.2459*10 3 where: ? x = capacitance/capacitance55rh ? capacitance55rh is the capacitance at 55%.
revision history AN4232 16/17 docid024134 rev 2 3 revision history table 3. document revision history date revision changes 31-jan-2013 1 initial release. 29-jan-2015 2 extended the applicability to stm3 2f302xd/e and stm32f303xd/e. updated: ? introduction ? table 1: applicable products ? section 1.1: hysteresis , ? section 1.2: propagation delay (response time) , ? section 2.4: preventing false over-cu rrent detections in motor control applications ? section 2.5: humidity measurement
docid024134 rev 2 17/17 AN4232 17 important notice ? please read carefully stmicroelectronics nv and its subsidiaries (?st?) reserve the right to make changes, corrections, enhancements, modifications, and improvements to st products and/or to this document at any time without notice. purchasers should obtain the latest relevant in formation on st products before placing orders. st products are sold pursuant to st?s terms and conditions of sale in place at the time of o rder acknowledgement. purchasers are solely responsible for the choice, selection, and use of st products and st assumes no liability for application assistance or the design of purchasers? products. no license, express or implied, to any intellectual property right is granted by st herein. resale of st products with provisions different from the information set forth herein shall void any warranty granted by st for such product. st and the st logo are trademarks of st. all other product or service names are the property of their respective owners. information in this document supersedes and replaces information previously supplied in any prior versions of this document. ? 2015 stmicroelectronics ? all rights reserved


▲Up To Search▲   

 
Price & Availability of AN4232

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X